home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0924.ZIP
/
SINPLOT
< prev
next >
Wrap
Text File
|
1988-01-10
|
2KB
|
82 lines
/* TEST PLOTTING PROGRAM FOR SIN */
/* Requires ANSI.SYS loaded for graphics */
#include smio.h
main() { static int i, j;
scrgraf();
putstr ("Demonstration SIN plot.\n");
for (i = 0; i < 360; i += 30)
sinplot ( (float) i);
for (i = 0; i < 300; i++ )
for (j = 0; j < 300; j++ ) j;
scrtxt();
}
sinplot (off) float off;
{ float f, sin(); f = -300.;
plot ( 20, (int) (100. + 90. * sin (f + off)), 1);
while ( (f += 3.) <= 300. )
lplot ( (int) (320. + f),
(int) (100. + 90. * sin (f + off)), 1); }
/* PLOTTING ROUTINES */
scrgraf() { putstr ("\33[=6h"); } /* Graphics screen set and clear */
scrtxt() { putstr ("\33[=2h"); } /* Text screen set */
/* Line plotting - draw from last position to x, y */
lplot (x, y, t) int x, y, t;
{ int xi, yi, mx, mn, dx, dy, mt, cc, i;
xi = yi = 1;
if ( (dx = x - _grx) < 0 ) { dx = -dx; xi = -1; }
if ( (dy = y - _gry) < 0 ) { dy = -dy; yi = -1; }
mt = (dx > dy); mx = mt ? dx : dy; mn = mt ? dy : dx;
for ( cc = mx >> 1, i = 0; i < mx; i++ )
{ if ( (cc += mn) > mx )
{ plot ( _grx + xi, _gry + yi, t); cc -= mx; }
else plot ( _grx + (mt ? xi : 0), _gry + (mt ? 0 : yi), t); } }
/* Plot a single pixel on 640 x 200 screen -
t = 0: move only, t = 1: plot,
t = 2: xorplot, t = -1: unplot */
plot (x, y, t) int x, y, t;
{ static int ad, mm;
_grx = x; _gry = y;
if (!t) return;
if ( _grx < 0 || _grx >= 640 ) return;
if ( _gry < 0 || _gry >= 200 ) return;
ad = 80 * (_gry >> 1) + (_grx >> 3)
+ ( (_gry & 0x01) ? 0x2000 : 0 );
mm = 0x80 >> (_grx & 0x07);
if (t<0)
/* epoke (epeek(0xB800, ad) & ~mm, 0xB800, ad); */
inline ( 0x06, 0xBB, 0xB800,
0x8E, 0xC3, 0x8B, 0x1E, &ad,
0xA0, &mm, 0x34, 0xFF, 0x26, 0x20, 0x07, 0x07);
else if (t==1)
/* epoke (epeek(0xB800, ad) | mm, 0xB800, ad); */
inline ( 0x06, 0xBB, 0xB800,
0x8E, 0xC3, 0x8B, 0x1E, &ad,
0xA0, &mm, 0x26, 0x08, 0x07, 0x07 );
else
/* epoke (epeek(0xB800, ad) ^ mm, 0xB800, ad); */
inline ( 0x06, 0xBB, 0xB800,
0x8E, 0xC3, 0x8B, 0x1E, &ad,
0xA0, &mm, 0x26, 0x30, 0x07, 0x07 ); }
#include ?smfps.lib
#include ?smio.lib